package com.tjhzzx.danfossNiagaraCore.command;


import com.tjhzzx.danfossNiagaraCore.servlet.AbstractServletCommand;
import com.tjhzzx.danfossNiagaraCore.servlet.impl.BTlsWebServer;

import javax.baja.collection.BITable;
import javax.baja.collection.TableCursor;
import javax.baja.naming.BOrd;
import javax.baja.sys.BIObject;
import javax.baja.sys.Sys;
import javax.baja.web.WebOp;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Luc
 * @date 2020-02-02 14:56 
 * @version 1.0
 */
public class TlsWebServerCommand extends AbstractServletCommand {

    public void getInstanceInJson(WebOp op, String queryString) {
        StringBuilder bql = new StringBuilder();
        bql.append("station:|slot:/Services|bql:select * from danfossNiagaraCore:TlsWebServer");
        List<BTlsWebServer> tlsWebServers = new ArrayList<>();
        BOrd ord = BOrd.make(bql.toString());
        BITable<BIObject> tlsWebServerTable = (BITable<BIObject>) ord.get(Sys.getStation());
        try (TableCursor<BIObject> cursor = tlsWebServerTable.cursor()) {
            while (cursor.next()) {
                BTlsWebServer tlsWebServer = (BTlsWebServer) cursor.get();
                tlsWebServers.add(tlsWebServer);
            }
        }
//        Map<String, Object> entity = new HashMap<>();
//        if(tlsWebServers.size() > 0) {
//            BTlsWebServer tlsWebServer = tlsWebServers.get(0);
//            entity.put("title", tlsWebServer.getTitle());
//            entity.put("enTitle", tlsWebServer.getEnTitle());
//            entity.put("dashboardRoot", tlsWebServer.getDashboardRoot());
//            entity.put("subSystemsRoot", tlsWebServer.getSubSystemsRoot());
//        }
//        BTlsWebServer tlsWebServer = tlsWebServers.get(0);
//        JSONObject jsonObject = new JSONObject(entity);
//        System.out.println("getInstanceInJson: " + JSON.toJSONString(tlsWebServer));
//        jsonResponse(JSONResult.success().add("tlsWebServer", jsonObject));
    }
}
